from loaddata import config
import pymongo
from urllib import parse
'''
mongodb数据库
2024年12月21日16:47:27
'''

class MongoDatabase:
    def __init__(self):
        t = config.getdbconfig()
        if t == 'wudi':
            # # 连接 MongoDB
            client = pymongo.MongoClient("mongodb://localhost:27017/")
            # # 创建数据库
            self.db = client.wudi
        else:
            # 转义用户名和密码
            username = parse.quote_plus("root")  # MongoDB账户名称
            password = parse.quote_plus("ZwOYRIkj4rsbMCsD")  # MongoDB账户密码
            # # 创建MongoDB客户端对象并指定SSL上下文（可选）
            # # client = pymongo.MongoClient(f"mongodb://{username}:{password}@{host}:{port}/")
            client = pymongo.MongoClient("mongodb://{0}:{1}@39.98.110.118:27017/lottery_data_his".format(username, password))
            self.db = client.lottery_data_his